<?php
/**
 * Miffos framework
 * ----------------------------------------------
 *
 * Copyright (c) 2008, 2009 Martin Sadový (http://sodae.cz)
 *
 * This source file is subject to the "Miffos license" that is bundled
 * with this package in the file license.txt.
 *
 * @copyright  Copyright (c) 2008, 2009 Martin Sadový
 * @license    license.txt
 * @link       http://miffos.sodae.cz
 * @package    miffos
 * @version    $Id$
 */


class Tools{
    /**
     * convert array to object
     * @param array $array
     * @param bool $sub
     */
    public static function array2object($array,$sub=false)
    {
        $object = stdClass;
        if(count($array) == 0) 
           return $object; // if array not have key => return

        foreach($array as $key=>$value){
            $object->$key = (is_array($value) AND $sub)?self::array2object($value,$sub):$value;
        }
        return $object;
    }

    /**
     * convert object to array
     * @param object $object
     * @param bool $sub
     */
    public static function object2array($object,$sub=false)
    {

        $array = array();

        foreach($object as $key=>$value){

            $array[$key] = (is_object($value) AND $sub)?self::object2array($value,$sub):$value;

        }

        return $array;

    }
}
        
?>